﻿//
// <author>David Nohejl</author>
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPFTrees.DataStructures;
using WPFTrees.Parser;

namespace WPFTrees
{
    /// <summary>
    /// Implementace IComparer porovnavajici podle celkoveho poctu uzlu 
    /// v podstromu.
    /// </summary>
    /// <remarks>Pouziva se v Ladderize metodach.</remarks>
    class CladeSizeComparer:IComparer<NTreeNode<NewickNode>>
    {
        bool bReverse;

        /// <summary>
        /// Vytvori novou instanci CladeSizeComparer.
        /// </summary>
        /// <param name="reverse">true pokud se ma poradi porovnani otocit.
        /// </param>
        public CladeSizeComparer(bool reverse)
        {
            bReverse = reverse;
        }

        /// <summary>
        /// Porovna dve instance NTreeNode&lt;NewickNode&gt;
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public int Compare(NTreeNode<NewickNode> x, NTreeNode<NewickNode> y)
        {
            int res = x.CountChildren.CompareTo(y.CountChildren);
            if (bReverse)
                return -res;
            else return res;
        }
    }
}
